@isTest
private class CreateReturnOrderControllerTest{
	
    static testMethod void testMethod1() {
    	Account acc = TestUtils.createAccount();
        insert acc;

        //创建出库单
        ExWarehouse__c wh = new ExWarehouse__c();
        wh.Account__c = acc.Id;
        insert wh;
        
        //创建产品
        Product__c p1 = new Product__c();
        insert p1;
        //创建出库明细
        ExWarehouse_Detail__c whd = new ExWarehouse_Detail__c();
        whd.ExWarehouse__c = wh.Id;
        whd.Product__c = p1.Id;
        whd.nnum__c = 5;
        insert whd;
        //创建退货单
        ExWarehouse__c re = new ExWarehouse__c();
        re.Account__c = acc.Id;
        re.ReturnRelationExhouse__c = wh.Id;
        re.IsReturnOrder__c = true;
        re.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('退货申请单', 'ExWarehouse__c');
        insert re;
        //创建退货明细单
        ExWarehouse_Detail__c rd = new ExWarehouse_Detail__c();
        rd.ExWarehouse__c = re.Id;
        rd.IsReturnDetail__c = true;
        rd.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('退货单明细', 'ExWarehouse_Detail__c');
        ///退货2个
        rd.ReturnNum__c = 2;
        insert rd;
        
        //
		PageReference page = new PageReference('/apex/CreateReturnOrderController?id=' + wh.Id);
        System.Test.setCurrentPage(page);
        CreateReturnOrderController ro = new CreateReturnOrderController(new ApexPages.StandardController(wh));
        ro.init();
        System.debug(ro.baseInfo.isReinvoice);

        ro.baseInfo.isReinvoice = false;
        System.assertEquals(1, ro.ds.size());
        
        for( CreateReturnOrderController.EXWareHouseDetail ex : ro.ds){
            ///退货1个
            ex.isReturning = true;
        	ex.willReturnNum = '1' ;
        }
        ro.save1();
        
        System.debug(wh.Id);
        List<ExWarehouse__c> res = [select Id from ExWarehouse__c where ReturnRelationExhouse__c = :wh.Id];
      	System.assertEquals(2, res.size());

        
    }

    
}